package cn.ubeta.b2c;

import cn.ubeta.b2c.R;
import cn.ubeta.b2c.bean.FoundInfo;
import cn.ubeta.b2c.bean.PriceInfo;
import cn.ubeta.b2c.bean.ProductInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by denny on 2016/10/20.
 */

public class EmbeddedData {

    public final static int BRAND_HAOQING = 1;
    public final static int BRAND_BONG = 2;
    public final static int BRAND_AHOME = 3;
    public final static int BRAND_ZHONGPAI = 4;
    public final static int BRAND_MUNISIDAN = 5;
    private static final int BRAND_LEHEJU = 6;
    private static final int BRAND_YOUMANJIA = 7;

    private final static ProductInfo[] infos = {
            // ======================== 好轻(4) ========================
            $(
                    10545117323L,
                    "中派 真皮沙发",
                    "抛光实木框架，坚固耐用\n" +
                            "柔软黄牛皮手感舒适\n" +
                            "电镀五金脚，稳定结实\n" +
                            "高密度海绵弹性好",
                    BRAND_ZHONGPAI,
                    R.drawable.ar_icon,
                    new int[] {R.drawable.ar_icon, R.drawable.ar_icon, R.drawable.ar_icon}
            ),
            $(
                    1380798140L,
                    "慕尼思丹 真皮沙发组合",
                    "搭配主流家居色彩，百搭又个性\n" +
                            "饱满外观造型，边几储物能力出众\n" +
                            "运用人体工学设计，舒适享受",
                    BRAND_MUNISIDAN,
                    R.drawable.ar_icon,
                    new int[] {R.drawable.ar_icon, R.drawable.ar_icon, R.drawable.ar_icon}
            )
    };

    //private final static Map<Long,ProductInfo> productInfos = new HashMap<>();
    private final static List<ProductInfo> productInfos = new ArrayList<>();

    static {
        for (ProductInfo info : infos) {
            //productInfos.put(info.getSkuId(), info);
            productInfos.add(info);
        }
    }

    /**
     * 获取skuId
     * @param brandId
     * @return
     */
    public static String getSkuIdsByBrand(int brandId) {
        StringBuilder sb = new StringBuilder();
        for (ProductInfo info : infos) {
            if (brandId == 0 || brandId == info.getBrandId()) {
                if (sb.length() > 0)
                    sb.append(",");
                sb.append(String.valueOf((info.getSkuId())));
            }
        }
        return sb.toString();
    }

    public static String getSkuIdsByBrand(int brandId, boolean withOneStock) {
        StringBuilder sb = new StringBuilder();
        for (ProductInfo info : infos) {
            if (brandId == 0 || brandId == info.getBrandId()) {
                if (sb.length() > 0)
                    sb.append(";");
                sb.append(String.valueOf((info.getSkuId())));
                if (withOneStock)
                    sb.append(",1");
            }
        }
        return sb.toString();
    }

    /**
     * 填充价格
     * @return
     */
    public static List<ProductInfo> fillPriceInfo(int brandId, List<PriceInfo> priceInfos) {
        List<ProductInfo> data = new ArrayList<>();
        for (ProductInfo productInfo : infos) {
            if (brandId == 0 || productInfo.getBrandId() == brandId) {
                if (priceInfos != null) {
                    for (PriceInfo priceInfo : priceInfos) {
                        if (priceInfo.getSkuId() == productInfo.getSkuId()) {
                            productInfo.setPriceInfo(priceInfo);
                            data.add(productInfo);
                            break;
                        }
                    }
                } else {
                    //productInfo.setPriceInfo(new PriceInfo());
                    data.add(productInfo);
                }
            }
        }
        return data;
    }

    private static ProductInfo $(long skuId, String name, String desc, int brandId, int listImg, int[] detailImg) {
        return $(false, skuId, name, desc, brandId, listImg, detailImg);
    }

    private static ProductInfo $(boolean model, long skuId, String name, String desc, int brandId, int listImg, int[] detailImg) {
        return new ProductInfo(skuId, name, desc, brandId, listImg, detailImg, model);
    }

    /**
     * 按品牌获取商品
     * @param brandId
     * @param limited
     * @return
     */
    public static List<ProductInfo> getBrandProduct(long skuId, int brandId, int limited) {
        List<ProductInfo> data = new ArrayList<>();
        for (ProductInfo info : infos) {
            if (info.getBrandId() == brandId && info.getSkuId() != skuId)
                data.add(info);
            if (data.size() >= limited)
                break;
        }
        return data;
    }

    /**
     * 获取所有品牌
     * @return
     */
    public static List<FoundInfo> getBrands(boolean all) {
        List data = new ArrayList();
        data.add(new FoundInfo(BRAND_AHOME, "A家", R.drawable.ar_icon));
        data.add(new FoundInfo(BRAND_LEHEJU, "乐和居", R.drawable.ar_icon));
        if (all) {
            data.add(new FoundInfo(BRAND_HAOQING, "好轻", R.drawable.ar_icon));
            data.add(new FoundInfo(BRAND_BONG, "Bong 3", R.drawable.ar_icon));
        }
        return data;
    }

    /**
     * 通过skuId获取商品名字
     * @param skuId
     * @return
     */
    public static String getName(long skuId) {
        if (skuId == 0)
            return "";
        for (ProductInfo info : infos) {
            if (skuId == info.getSkuId()) {
                return info.getName();
            }
        }
        for (Long sku : otherNames.keySet()) {
            if (skuId == sku) {
                return otherNames.get(sku);
            }
        }
        return "";
    }

    /**
     * 通过skuId获取商品图片
     * @param skuId
     * @return
     */
    public static int getResImg(long skuId) {
        if (skuId == 0)
            return 0;
        for (ProductInfo info : infos) {
            if (skuId == info.getSkuId()) {
                return info.getListImg();
            }
        }
        for (Long sku : otherImgs.keySet()) {
            if (skuId == sku) {
                return otherImgs.get(sku);
            }
        }
        return 0;
    }

    static Map<Long, Integer> otherImgs = new HashMap<>();
    static {
        otherImgs.put(2060618L, R.drawable.tmp_imac);
        otherImgs.put(1856583l, R.drawable.tmp_iphone_deep_grey);
        otherImgs.put(1856581L, R.drawable.tmp_iphone_gold);
        otherImgs.put(1856584L, R.drawable.tmp_iphone_rose_gold);
        otherImgs.put(1856582L, R.drawable.tmp_iphone_silver);
        otherImgs.put(1378536L, R.drawable.tmp_macbook);
    }

    static Map<Long, String> otherNames = new HashMap<>();
    static {
        otherNames.put(2060618L, "Apple iMac 21.5英寸一体机（双核 Core i5 处理器/8GB内存/1TB存储 MK142CH）");
        otherNames.put(1856583L, "Apple iPhone 6s (A1700) 16G 深空灰色 移动联通电信4G手机");
        otherNames.put(1856581L, "Apple iPhone 6s (A1700) 16G 金色 移动联通电信4G手机");
        otherNames.put(1856584L, "Apple iPhone 6s (A1700) 16G 玫瑰金色 移动联通电信4G手机");
        otherNames.put(1856582L, "Apple iPhone 6s (A1700) 16G 银色 移动联通电信4G手机");
        otherNames.put(1378536L, "Apple MacBook Air 11.6英寸笔记本电脑 银色(Core i5 处理器/4GB内存/128GB SSD闪存 MJVM2CH)");
    }

    // 第三方skuId
    static Map<String, List<Long>> mMapThirtyPart = new HashMap<>();

    static {
        List<Long> list = new ArrayList<>();
        list.add(10545117323L);
        list.add(10018658753L);
        list.add(1785274295L);
        mMapThirtyPart.put("ISTAGING", list);

        list = new ArrayList<>();
        list.add(1380798140L);
        list.add(10968071726L);
        list.add(1567535749L);
        list.add(1162644482L);
        list.add(1111451518L);
        mMapThirtyPart.put("易绚", list);
    }

    /**
     * 是否第三方sku
     * @param skuId
     * @return
     */
    public static String getThirtyPart(int brandId, long skuId) {
//        if (brandId == BRAND_ZHONGPAI) {
//            return "ISTAGING";
//        } else if (brandId == BRAND_MUNISIDAN) {
//            return "易绚";
//        }
//        return null;

        for (String thirtyPart : mMapThirtyPart.keySet()) {
            List<Long> list = mMapThirtyPart.get(thirtyPart);
            if (list != null && list.size() > 0) {
                if (list.contains(skuId)) {
                    return thirtyPart;
                }
            }
        }
        return null;
    }
}
